package persistency.controller;

import java.util.ArrayList;
import java.util.Collection;

import model.Business;
import model.BusinessTypeEnum;
import model.Course;
import model.CourseHistory;
import model.FreeStudent;
import model.Teacher;
import persistency.ArgIO;

public class FreeStudentController extends BusinessController{
	private StringBuilder callableStatement;

	
	private static FreeStudentController instance = new FreeStudentController();
	private FreeStudentController(){}
	
	public static FreeStudentController instance(){
		return instance;
	}
	
	public boolean insertFreeStudent(FreeStudent freeStudent) {
		callableStatement = new StringBuilder("{call sp_insertfreestudent(?,?)}");
		return insert(freeStudent,callableStatement,2);
	}

	public FreeStudent getFreeStudent(String id){
		return (FreeStudent)getBusinessObject(id,new StringBuilder("{call sp_getbyidfreestudent(?)}"),BusinessTypeEnum.FREESTUDENT);
	}
	
	public Collection<FreeStudent> getAll() {
		Collection<FreeStudent> col = new ArrayList<FreeStudent>();
		col.addAll((Collection<? extends FreeStudent>) getBusinessObjects(new StringBuilder("{call sp_getallfreestudent}"),BusinessTypeEnum.FREESTUDENT));
		return col;
	}
	
	@Override
	public void prepare(Business business, Object[] args, int[] argsType, ArgIO[] argsIO, int i) throws Exception {
		/*
		 in studentnumber varchar(25),
    in nationality varchar(25)
		 */
		
		FreeStudent freeStudent = (FreeStudent) business;
		switch (i) {
		case 0: {
			args[i] = freeStudent.getStudentNumber();
			argsType[i] = java.sql.Types.CHAR;
			argsIO[i] = ArgIO.IN;
			break;
		}
		case 1: {
			args[i] = freeStudent.getNationality();
			argsType[i] = java.sql.Types.CHAR;
			argsIO[i] = ArgIO.IN;
			break;
		}
		default:
			throw new Exception("Error while creating SP createCourse");
		}
		
	}
}
